<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column fixed prop="id" label="文章id" width="120"/>
    <el-table-column prop="authorId" label="用户Id" width="120" />
    <el-table-column prop="title" label="文章标题" width="300" />
    <el-table-column prop="summary" label="简介" width="400" />
<!--    <el-table-column prop="coverImage" label="图片" width="100">-->
<!--      <template v-slot:default="scope">-->
<!--        <el-image :src="this.tableData.image+scope.row.coverImage"/>-->
<!--      </template>-->
<!--    </el-table-column>-->
    <el-table-column prop="viewCounts" label="浏览量" width="50" />
    <el-table-column prop="commentCounts" label="评论数量" width="50" />
    <el-table-column fixed="right" label="Operations" width="150">
      <template #default>
        <el-button link type="primary" size="small" @click="handleClick">查看
        </el-button>
        <el-button link type="primary" size="small">修改
        </el-button>
        <el-button link type="primary" size="small">删除
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>

import request from "@/utils/request";
import router from "@/router";

export default {
  name: "ArticleTable",
  components: {},

  created() {
    this.load()
  },

  methods: {
    load() {
      let user = sessionStorage.getItem("User")
      this.userId = JSON.parse(user).userId
      request.get("/articles/articleSelectByUserId/"+this.userId+"/"+this.current).then(res => {
        console.log(res.data)
        if (res.data == 500) {
          alert("用户id返回错误,返回推荐页面!")
          router.push("/CommentView")
        } else {
          if (res.data.records!=null){
          this.tableData=res.data.records
          this.total=res.data.total
          this.size=res.data.size
          this.pages=res.data.pages
          }
          else {
            this.tableData=res.data
          }
        }
      })
    },

  },

  data(){
    return{
      tableData:[
        {
          id:'',
          authorId:'',
          title:'',
          summary:'',
          image:'http://localhost:8888/articleimages/',
          coverImage:'',
          weight:'',
          viewCounts:'',
          commentCounts:'',
        }
      ],

      userId: '',
      total: 6,
      size: 12,
      current: 1,
      pages: 10,
    }
  }
}


</script>
